package bean;
import java.math.BigDecimal;

import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

import com.sun.org.apache.xerces.internal.impl.xpath.regex.ParseException;

public class Util {

	;

		  public static  final int NOVO=1;
		  public static  final int EXPORTAR=2;
		  public static  final int REPLICAR=3;
		  public static  final int VOLTAR=4;
		  public static  final int AVANCAR=5;
		  public static  final int CANCELAR=6;
		  public static  final int OK=7;
		  
		private static final NumberFormat formato = NumberFormat.getInstance(Locale.getDefault());
			
		
		
		public static String getDoubleFormatLocal(double valor) {
			 try {
				 if(valor==0){
					 return  "0,00" ; 
				 }else{
			     return  formato.format(valor) ;
				 }
			      
			    } catch (Exception e) {
			    	
			    	  return null;
			    }
			
		}
		
		public static int parseInt(String valor) {
			 try {
				 if(valor!= null && !valor.isEmpty()){
					 return  Integer.parseInt(valor) ; 
				 }else{
			     return  0 ;
				 }
			      
			    } catch (NumberFormatException e) {
			    	e.printStackTrace();
			    	  return 0;
			    }
			
		}
		public static long parseLong(String valor) {
			 try {
				 if(valor!= null && !valor.isEmpty()){
					 return  Long.parseLong(valor) ; 
				 }else{
			     return  0 ;
				 }
			      
			    } catch (NumberFormatException e) {
			    	e.printStackTrace();
			    	  return 0;
			    }
			
		}
		 public double  testRound(double valor,int decimalPlace){  
		         
		      
		       BigDecimal bd = new BigDecimal( valor);  
		      bd = bd.setScale(decimalPlace,BigDecimal.ROUND_HALF_UP);  
		      return bd.doubleValue();  
		      
		       }  
		 
		public static double getDoubleFormatPadrao(String valorDouble) {
			 try {
				 
				 System.out.print(formato.parse(valorDouble).doubleValue());
			     return formato.parse(valorDouble).doubleValue()  ;
			     
			      
			    } catch (Exception e) {
			    	e.printStackTrace();
			    	  return 0.0;
			    }
			
		}
		
		public static int convetNmeroInt(String valor) {
			 try {
				
		
			     return  Integer.parseInt(valor.replaceAll("[\\D]",""))  ;
			      
			    } catch (Exception e) {
			    	e.printStackTrace();
			    	  return 0;
			    }
			
		}
		public static long convetNmeroLon(String valor) {
			 try {
				
		
			     return  Long.parseLong(valor.replaceAll("[\\D]",""))  ;
			      
			    } catch (Exception e) {
			    	
			    	  return 0;
			    }
			
		}
		public static String formatDatadd_mm_aaaaa(Timestamp data) {
			 try {
				 String datd ="";
				 if (data != null) {
					 datd = new SimpleDateFormat("dd/MM/yyyy").format(data);
					
				}
		
			     return datd;
			      
			    } catch (Exception e) {
			    	e.printStackTrace();
			    	  return  "";
			    }
			
		}
		
		public static Date convertaStringDate (String data){
		
			  
			DateFormat df = new SimpleDateFormat("dd/MM/yyyy");
			  
	        try
	        {
	            Date today = df.parse("20/12/2005");           
	           System.out.println("Today = " + df.format(today));
	        } catch (ParseException e)
	        {
	            e.printStackTrace();
	       } catch (java.text.ParseException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			return null;
		}
		 public static String dataParaString(Date data){  
			// String df = new SimpleDateFormat("dd/MM/yyyy").format(data);

			
			 try {
				 String datd ="";
				 if (data != null) {
					 datd = new SimpleDateFormat("dd/MM/yyyy").format(data);
					
				}
		
			     return datd;
			      
			    } catch (Exception e) {
			    	e.printStackTrace();
			    	  return  "";
			    }
		 
			
		     }

	
}
